<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
    <input type="text" placeholder="输入数字1" id="i1"></input><br>
    <input type="text" placeholder="输入数字2" id="i2"></input><br>
    <button onclick="calc('+')">+</button>
    <button  onclick="calc('-')">-</button>
    <button onclick="calc('*')">*</button>
    <button onclick="calc('/')">%</button>
    <br>
<h3>输入结果：<span></span></h3>
<script>
    function calc(o)
    {
        let q1=document.querySelector("#i1").value;
        let q2=document.querySelector("#i2").value;
        let n1=parseFloat(q1);
        let n2=parseFloat(q2);
        let sp=document.querySelector('span');

        switch (o)
        {
            case '+': sp.innerHTML=n1+n2;break;//innerHTML 设置当前标签内部置
            case '-': sp.innerHTML=n1-n2;break;
            case '*': sp.innerHTML=n1*n2;break;
            case '/':if(n2==0){alert("除数不能为0")}else{ sp.innerHTML=n1/n2;break;}

        }
    }
</script>
</body>
</html>